package com.weichen.studentgameexchange.message.controller;

import cn.hutool.core.util.StrUtil;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.message.entity.Message;
import com.weichen.studentgameexchange.message.entity.MessageType;
import com.weichen.studentgameexchange.message.entity.vo.MessageVo;
import com.weichen.studentgameexchange.message.service.IMessageTypeService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-08
 */
@RestController
@RequestMapping("/message/messageType")
public class MessageTypeController {

    @Autowired
    IMessageTypeService messageTypeService;

/**
 * TODO 管理员-消息管理--消息类型
 */
    /**
     * 管理员分页查询消息类型
     * @param keyword
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询消息类型接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam("keyword") String keyword,
                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size){
        return messageTypeService.adminPage(keyword ,page ,size );
    }

    /**
     * 管理员新增消息类型
     * @param messageType
     * @return
     */
    @Operation(summary = "管理员新增消息类型接口")
    @PostMapping("/admin/add")
    public Result adminAdd(@RequestBody MessageType  messageType){
        messageTypeService.save(messageType);
        return Result.success();
    }

    /**
     * 管理员查看单个游戏消息类型
     * @param messageId
     * @return
     */
    @Operation(summary = "管理员查看单个消息类型接口")
    @GetMapping("/admin/selectOne/{messageId}")
    public Result adminSelectOne(@PathVariable("messageId") Long messageId){
        if (StrUtil.isBlankIfStr(messageTypeService.getById(messageId)))
            return Result.error("消息类型不存在！");
        return Result.success(messageTypeService.getById(messageId));
    }

    /**
     * 管理员修改消息类型
     * @param messageType
     * @return
     */
    @Operation(summary = "管理员修改消息类型接口")
    @PutMapping("/admin/update")
    public Result adminUpdate(@RequestBody MessageType messageType){
        messageTypeService.updateById(messageType);
        return Result.success();
    }

    /**
     * 管理员删除单个消息类型
     * @param typeId
     * @return
     */
    @Operation(summary = "管理员删除单个消息类型接口")
    @DeleteMapping("/admin/delete/{typeId}")
    public Result adminDeleteOne(@PathVariable("typeId") Long typeId){
        if (StrUtil.isBlankIfStr(messageTypeService.getById(typeId)))
            return Result.error("消息类型不存在！");
        return messageTypeService.adminDeleteOne(typeId);
    }

    /**
     * 管理员批量删除多个消息类型
     * @return
     */
    @Operation(summary = "管理员批量删除多个消息类型接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> typeIds){
        typeIds.forEach(this::adminDeleteOne);
        return Result.success();
    }
}

